package com.vanke.house.task;

import com.vanke.house.service.spider.HouseSpider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author fangyu
 * @version v1.0.0
 * @date 2020/6/18 8:48 下午
 */
@Slf4j
@Component
public class SpiderTask {

    @Autowired
    private HouseSpider houseSpider;

    @Scheduled(cron = "0 0 12 * * ?")
    public void saleSpiderTask() throws Exception {
        log.info("start crawl");
        String url = "https://wh.ke.com/chengjiao/a2c3711064009711/?sug=%E4%B8%87%E7%A7%91%E9%87%91%E8%89%B2%E5%9F%8E%E5%B8%82K3%E5%9C%B0%E5%9D%97";
//        String url = "https://wh.ke.com/ershoufang/c3711064009711/?sug=%E4%B8%87%E7%A7%91%E9%87%91%E8%89%B2%E5%9F%8E%E5%B8%82K3%E5%9C%B0%E5%9D%97";
//        String url = "https://wh.ke.com/ershoufang/co32ba79ea81c3711064009711/?sug=%E4%B8%87%E7%A7%91%E9%87%91%E8%89%B2%E5%9F%8E%E5%B8%82K3%E5%9C%B0%E5%9D%97";
        houseSpider.crawl(url, "chenjiao");
        log.info("finish crawl");
    }

    @Scheduled(fixedRate=60000)
    public void dealSpiderTask() throws Exception {
        log.info("start crawl");
//        String url = "https://wh.ke.com/chengjiao/pg2a2c3711064009711/?sug=%E4%B8%87%E7%A7%91%E9%87%91%E8%89%B2%E5%9F%8E%E5%B8%82K3%E5%9C%B0%E5%9D%97";
//        String url = "https://wh.ke.com/ershoufang/c3711064009711/?sug=%E4%B8%87%E7%A7%91%E9%87%91%E8%89%B2%E5%9F%8E%E5%B8%82K3%E5%9C%B0%E5%9D%97";
        String url = "https://wh.ke.com/ershoufang/co32ba79ea81c3711064009711/?sug=%E4%B8%87%E7%A7%91%E9%87%91%E8%89%B2%E5%9F%8E%E5%B8%82K3%E5%9C%B0%E5%9D%97";
        houseSpider.crawl(url, "ershou");
        log.info("finish crawl");
    }
}
